﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NeuralNetwork.Activation
{
    abstract public class Function
    {
        abstract public double Call(double d);
        abstract public double Derivative(double d);
    }

    public class Linear : Function
    {
        private double constant = 0;
        public double Constant
        {
            get { return constant; }
            set { constant = value; }
        }

        override public double Call(double d) 
        { 
            return d; 
        }

        override public double Derivative(double d) 
        { 
            return constant;
        }
    }

    public class Sigmoid : Function
    {
        override public double Call(double d) 
        { 
            return 1.0 / (1 + Math.Exp(-d)); 
        }

        override public double Derivative(double d)
        { 
            return d * (1.0 - d);
        }
    }

    public class HyperbolicTangent : Function
    {
        override public double Call(double d) 
        { 
            double e2d = Math.Exp(2.0 * d);
            return (e2d - 1.0)/(e2d + 1.0); 
        }

        override public double Derivative(double d)
        { 
            return (1.0 - Math.Pow(Call(d), 2.0));
        }
    }

}
